package com.yc.config;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class OSSConfig {
    @Value("${aliyun.oss.endpoint}")
    private String endpoint;
    @Value("${aliyun.oss.accessKeyId}")
    private String accessKeyId;
    @Value("${aliyun.oss.accessKeySecret}")
    private String accessKeySecret;
    @Value("${aliyun.oss.bucketName}")
    private String bucketName;

    // 允许的文件类型（MIME类型）
    private static final String[] ALLOWED_MIME_TYPES = {
            // 图片类型
            "image/jpeg", "image/png", "image/gif", "image/bmp", "image/webp",
            // PDF
            "application/pdf",
            // Word（.doc/.docx）
            "application/msword",
            "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
            // Excel（.xls/.xlsx）
            "application/vnd.ms-excel",
            "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
    };

    // 文件大小限制（单位：字节）
    private static final long MAX_SINGLE_FILE_SIZE = 10 * 1024 * 1024; // 10MB
    private static final long MAX_TOTAL_SIZE = 50 * 1024 * 1024;      // 50MB

    @Bean
    public OSS ossClient() {
        return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
    }

    // 以下是各配置的getter方法
    public String getBucketName() {
        return bucketName;
    }

    public String getEndpoint() {
        return endpoint;
    }

    public String[] getAllowedMimeTypes() {
        return ALLOWED_MIME_TYPES;
    }

    public long getMaxSingleFileSize() {
        return MAX_SINGLE_FILE_SIZE;
    }

    public long getMaxTotalSize() {
        return MAX_TOTAL_SIZE;
    }
}